package org.javaboy.meeting.controller;

import org.javaboy.meeting.mapper.EmployeeMapper;
import org.javaboy.meeting.model.Employee;
import org.javaboy.meeting.model.Meeting;
import org.javaboy.meeting.service.MyMeetingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@Controller
public class MyMeetingController {

    @Autowired
    MyMeetingService myMeetingService;

    @Autowired
    EmployeeMapper employeeMapper;

    /**
     * 我会议的详情
     * @param meetingid
     * @param model
     * @return
     */
    @RequestMapping({"mymeetingdetails","/admin/mymeetingdetails"})
    public String mymeetingdetails(Integer meetingid, Model model){
        Meeting mymeetingdetails = myMeetingService.findMyBookingDetailsByMeetingId(meetingid);
        List<Employee> emps = employeeMapper.getEmpByMeetingId(meetingid);
        model.addAttribute("mymeetingdetails",mymeetingdetails);
        model.addAttribute("emps",emps);
        return "mymeetingdetails";
    }

    /**
     * 取消会议
     * @param meetingid
     * @param model
     * @return
     */
    @RequestMapping({"/cancelmeeting","/admin/cancelmeeting"})
    public String cancelmeeting(Integer meetingid ,Model model){
//        System.out.println(meetingid);
        model.addAttribute("cancelmeeting",myMeetingService.findMyBookingDetailsByMeetingId(meetingid));
        return "cancelmeeting";
    }

    /**
     * 确认取消会议
     * @param meeting
     * @param session
     * @return
     */
    @RequestMapping({"/sureCancelMeeting","/admin/sureCancelMeeting"})
    public String sureCancelMeeting(Meeting meeting, HttpSession session){
        //状态1代表会议取消
        meeting.setStatus(1);

        //获得当前登录用户
        Employee currentuser = (Employee) session.getAttribute("currentuser");

        meeting.setCanceledtime(new Date());
        myMeetingService.sureCancelMeeting(meeting);
        return "redirect:/admin/mybookings?employeeid="+currentuser.getEmployeeid();

    }
}
